package net.loyintean.pearlshell.validation.rule;

import net.loyintean.pearlshell.validation.IValidRule;
import net.loyintean.pearlshell.validation.IValidRuleConfig;

public class StringMaxLengthValidRuleImpl extends AbstractStringValidRuleImpl
		implements IValidRule {

	@Override
	public boolean validString(String toValid, IValidRuleConfig config) {
		assert config != null;
		assert config.validParam() != null;
		assert config.validParam()[0] instanceof Integer;

		int maxLength = (Integer) config.validParam()[0];

		return toValid.length() <= maxLength;
	}

	@Override
	public String errorMsg(IValidRuleConfig config) {
		assert config != null;
		assert config.validParam() != null;
		assert config.validParam()[0] instanceof Integer;

		return "最大长度为" + config.validParam()[0];
	}

}
